/*     */ package com.kingdee.eas.lifetime.util.edcommonutils;
/*     */ 
/*     */ import com.kingdee.bos.util.backport.Collections;
/*     */ import com.kingdee.util.DateTimeUtils;
/*     */ import java.math.BigDecimal;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Comparator;
/*     */ import java.util.Date;
/*     */ import java.util.HashSet;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Random;
/*     */ import java.util.Set;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class EDcommonUtils
/*     */ {
/*  23 */   private static final Logger logger = Logger.getLogger(EDcommonUtils.class);
/*     */ 
/*     */   public static class BooleanUtils
/*     */   {
/*     */     static final String trueValue = "1";
/*     */     static final String falseValue = "0";
/*     */     static final String zuoKuoHao = "(";
/*     */     static final String youKuoHao = ")";
/*     */ 
/*     */     public static boolean getBooleanValue(String str)
/*     */     {
/* 590 */       String tempStr = str;
/* 591 */       if (EDcommonUtils.StringUtils.isEmpty(str)) {
/* 592 */         return false;
/*     */       }
/* 594 */       str = str.replaceAll(" ", "");
/* 595 */       str = str.replaceAll("true", "1");
/* 596 */       str = str.replaceAll("false", "0");
/* 597 */       if (((str.indexOf("&&") != -1) || (str.indexOf("||") != -1)) && 
/* 598 */         (str.indexOf("(") != 0)) {
/* 599 */         str = "(" + str + ")";
/*     */       }
/*     */ 
/* 602 */       int zuoCount = EDcommonUtils.StringUtils.findStrCount(str, "(");
/* 603 */       int youCount = EDcommonUtils.StringUtils.findStrCount(str, ")");
/* 604 */       if (zuoCount != youCount) {
/*     */       }
/* 607 */       int i = 1; for (int j = zuoCount; i <= youCount; j--) {
/* 608 */         String s1 = EDcommonUtils.StringUtils.findBetween(str, "(", j, ")", EDcommonUtils.StringUtils.getRightIndex(str, "(", j, 
/* 609 */           ")"));
/* 610 */         String s2 = convert(s1);
/* 611 */         while (s2.length() != 1) {
/* 612 */           s2 = convert(s1);
/* 613 */           s1 = s2;
/* 614 */           if ((s2.length() != 1) && (s2.indexOf("&&") == -1) && (s2.indexOf("||") == -1)) {
/*     */           }
/*     */         }
/* 618 */         int begin = EDcommonUtils.StringUtils.findSubStrIndex(str, "(", j);
/* 619 */         int end = EDcommonUtils.StringUtils.findSubStrIndex(str, ")", EDcommonUtils.StringUtils.getRightIndex(str, "(", j, ")"));
/* 620 */         StringBuffer buffer = new StringBuffer(EDcommonUtils.StringUtils.truncationString(str, begin, end));
/* 621 */         buffer.insert(begin, s2);
/* 622 */         str = buffer.toString();
/*     */ 
/* 607 */         i++;
/*     */       }
/*     */ 
/* 624 */       return "1".equals(str.trim());
/*     */     }
/*     */ 
/*     */     private static String convert(String str) {
/* 628 */       str = str.replaceAll("1\\|\\|1", "1");
/* 629 */       str = str.replaceAll("1\\|\\|0", "1");
/* 630 */       str = str.replaceAll("0\\|\\|1", "1");
/* 631 */       str = str.replaceAll("0\\|\\|0", "0");
/* 632 */       str = str.replaceAll("1\\&\\&1", "1");
/* 633 */       str = str.replaceAll("1\\&\\&0", "0");
/* 634 */       str = str.replaceAll("0\\&\\&1", "0");
/* 635 */       str = str.replaceAll("0\\&\\&0", "0");
/* 636 */       if (!verifyConvertString(str)) {
/* 637 */         throw new RuntimeException("解析Boolean公式出现错误,缺失逻辑项！");
/*     */       }
/* 639 */       return str;
/*     */     }
/*     */ 
/*     */     private static boolean verifyConvertString(String str)
/*     */     {
/* 649 */       String strTemp = EDcommonUtils.StringUtils.replaceAll(str, "(", "");
/* 650 */       strTemp = EDcommonUtils.StringUtils.replaceAll(strTemp, ")", "");
/* 651 */       strTemp = EDcommonUtils.StringUtils.replaceAll(strTemp, "&&", "XXX");
/* 652 */       strTemp = EDcommonUtils.StringUtils.replaceAll(strTemp, "\\|\\|", "XXX");
/* 653 */       String[] strTemps = strTemp.split("XXX");
/* 654 */       int countXXX = EDcommonUtils.StringUtils.findStrCount(strTemp, "XXX");
/* 655 */       int countNumber = 0;
/* 656 */       for (int i = 0; i < strTemps.length; i++) {
/* 657 */         String s1 = strTemps[i];
/* 658 */         if (EDcommonUtils.StringUtils.isEmpty(s1)) {
/*     */           continue;
/*     */         }
/* 661 */         countNumber++;
/*     */       }
/*     */ 
/* 664 */       return (strTemps == null) || (countNumber == countXXX + 1);
/*     */     }
/*     */   }
/*     */ 
/*     */   public static class IntegerUtils
/*     */   {
/*     */     public static final int DESC = 0;
/*     */     public static final int ASC = 1;
/*     */ 
/*     */     public static void sort(int[] number, int sortType)
/*     */     {
/* 692 */       boolean flag = true;
/* 693 */       for (int i = 0; (i < number.length - 1) && (flag); i++) {
/* 694 */         flag = false;
/* 695 */         for (int j = 0; j < number.length - i - 1; j++)
/* 696 */           if (1 == sortType) {
/* 697 */             if (number[(j + 1)] < number[j]) {
/* 698 */               swap(number, j + 1, j);
/* 699 */               flag = true;
/*     */             }
/*     */           } else {
/* 701 */             if ((sortType != 0) || 
/* 702 */               (number[(j + 1)] <= number[j])) continue;
/* 703 */             swap(number, j + 1, j);
/* 704 */             flag = true;
/*     */           }
/*     */       }
/*     */     }
/*     */ 
/*     */     static void swap(int[] number, int i, int j)
/*     */     {
/* 713 */       int t = number[i];
/* 714 */       number[i] = number[j];
/* 715 */       number[j] = t;
/*     */     }
/*     */ 
/*     */     public static int max(int[] tnis)
/*     */     {
/* 725 */       int temp = 0;
/* 726 */       if (tnis != null) {
/* 727 */         for (int i = 0; i < tnis.length; i++) {
/* 728 */           if (temp < tnis[i]) {
/* 729 */             temp = tnis[i];
/*     */           }
/*     */         }
/*     */       }
/* 733 */       return temp;
/*     */     }
/*     */ 
/*     */     public static int min(int[] tnis)
/*     */     {
/* 743 */       int temp = 0;
/* 744 */       if (tnis != null) {
/* 745 */         for (int i = 0; i < tnis.length; i++) {
/* 746 */           if (temp > tnis[i]) {
/* 747 */             temp = tnis[i];
/*     */           }
/*     */         }
/*     */       }
/* 751 */       return temp;
/*     */     }
/*     */   }
/*     */ 
/*     */   public static class ListUtil
/*     */   {
/*     */     public static boolean isEmpty(List list)
/*     */     {
/*  34 */       return (list == null) || (list.isEmpty());
/*     */     }
/*     */ 
/*     */     public static List copy(List src, List target)
/*     */     {
/*  44 */       ArrayList list = new ArrayList();
/*  45 */       int i = src.size();
/*     */       do { list.add(src.get(i));
/*     */ 
/*  45 */         i--; } while (i >= 0);
/*     */ 
/*  48 */       i = target.size();
/*     */       do { list.add(target.get(i));
/*     */ 
/*  48 */         i--; } while (i >= 0);
/*     */ 
/*  51 */       return list;
/*     */     }
/*     */ 
/*     */     public static List addList(List src, List target)
/*     */     {
/*  62 */       int i = 0; for (int k = src.size(); i < k; i++) {
/*  63 */         target.add(src.get(i));
/*     */       }
/*  65 */       return target;
/*     */     }
/*     */ 
/*     */     public static List convertObjectToList(Object objs)
/*     */     {
/*  75 */       ArrayList list = new ArrayList();
/*  76 */       if ((objs != null) && ((objs instanceof Object[]))) {
/*  77 */         Object[] objects = (Object[])objs;
/*  78 */         int i = objects.length;
/*     */         do { list.add(objects[i]); i--; } while (i >= 0);
/*     */       }
/*     */ 
/*  81 */       return list;
/*     */     }
/*     */ 
/*     */     public static List toSingleElement(List list)
/*     */     {
/*  91 */       ArrayList temp = new ArrayList(list.size());
/*  92 */       HashSet tempSet = new HashSet();
/*  93 */       int i = 0; for (int k = list.size(); i < k; i++) {
/*  94 */         tempSet.add(list.get(i));
/*     */       }
/*  96 */       Iterator it = tempSet.iterator();
/*  97 */       while (it.hasNext()) {
/*  98 */         temp.add(it.next());
/*     */       }
/* 100 */       return temp;
/*     */     }
/*     */   }
/*     */ 
/*     */   public static class MapUtil
/*     */   {
/*     */     public static boolean isEmpty(Map m)
/*     */     {
/* 110 */       return (m == null) || (m.isEmpty());
/*     */     }
/*     */ 
/*     */     public static List sortByKeyToList(Map map)
/*     */     {
/* 120 */       return sortByKeyToList(map, null);
/*     */     }
/*     */ 
/*     */     public static List sortByKeyToList(Map map, Comparator comparator)
/*     */     {
/* 130 */       List keyList = sortKey(map, comparator);
/* 131 */       ArrayList valueList = new ArrayList();
/* 132 */       int i = keyList.size();
/*     */       do { valueList.add(map.get(keyList.get(i)));
/*     */ 
/* 132 */         i--; } while (i >= 0);
/*     */ 
/* 135 */       return valueList;
/*     */     }
/*     */ 
/*     */     public static List sortKey(Map map, Comparator comparator)
/*     */     {
/* 146 */       if ((map == null) || (map.isEmpty())) {
/* 147 */         return null;
/*     */       }
/* 149 */       Iterator it = map.keySet().iterator();
/* 150 */       ArrayList keyList = new ArrayList();
/* 151 */       while (it.hasNext()) {
/* 152 */         keyList.add(it.next());
/*     */       }
/* 154 */       Collections.sort(keyList, comparator);
/* 155 */       return keyList;
/*     */     }
/*     */   }
/*     */ 
/*     */   public static class RandomUtils
/*     */   {
/* 558 */     private static Random random = new Random();
/*     */ 
/*     */     public static int getNumber(int min, int max)
/*     */     {
/* 568 */       int i = random.nextInt(max - min);
/* 569 */       return min + i;
/*     */     }
/*     */   }
/*     */ 
/*     */   public static class StringUtils
/*     */   {
/*     */     public static final String trueValue = "true";
/*     */     public static final String falseValue = "false";
/*     */     public static final String Equals = "==";
/*     */     public static final String Not_Equals = "!=";
/*     */     public static final String Greater = ">";
/*     */     public static final String Less = "<";
/*     */     public static final String Greater_Equals = ">=";
/*     */     public static final String Less_Equals = "<=";
/* 541 */     public static final String[] CompareExps = { "==", "!=", ">", "<", ">=", "<=" };
/*     */     public static final String Qie = "&&";
/*     */     public static final String Huo = "||";
/* 545 */     public static final String[] LogicExps = { "&&", "||" };
/*     */     public static final String MultiValueSign = "!!!!!";
/*     */ 
/*     */     public static String compareString(String str1, String str2, String sign)
/*     */     {
/* 176 */       if ((str1 == null) || (str2 == null)) {
/* 177 */         return "false";
/*     */       }
/* 179 */       str1 = str1.trim();
/* 180 */       str2 = str2.trim();
/*     */       try {
/* 182 */         Date date1 = DateTimeUtils.parseDate(str1);
/* 183 */         Date date2 = DateTimeUtils.parseDate(str2);
/* 185 */         if (">".equals(sign))
/* 186 */           return date1.compareTo(date2) == 1 ? "true" : "false";
/* 187 */         if ("<".equals(sign))
/* 188 */           return date1.compareTo(date2) == -1 ? "true" : "false";
/* 189 */         if ("==".equals(sign))
/* 190 */           return date1.compareTo(date2) == 0 ? "true" : "false";
/* 191 */         if ("!=".equals(sign))
/* 192 */           return date1.compareTo(date2) != 0 ? "true" : "false";
/* 193 */         if (">=".equals(sign))
/* 194 */           return date1.compareTo(date2) != -1 ? "true" : "false";
/* 195 */         if ("<=".equals(sign))
/* 196 */           return date1.compareTo(date2) != 1 ? "true" : "false";
/*     */       }
/*     */       catch (Exception isCompareStr) {
/*     */         try
/*     */         {
/* 203 */           BigDecimal d1 = new BigDecimal(str1);
/* 204 */           BigDecimal d2 = new BigDecimal(str2);
/* 206 */           if (">".equals(sign))
/* 207 */             return d1.compareTo(d2) == 1 ? "true" : "false";
/* 208 */           if ("<".equals(sign))
/* 209 */             return d1.compareTo(d2) == -1 ? "true" : "false";
/* 210 */           if ("==".equals(sign))
/* 211 */             return d1.compareTo(d2) == 0 ? "true" : "false";
/* 212 */           if ("!=".equals(sign))
/* 213 */             return d1.compareTo(d2) != 0 ? "true" : "false";
/* 214 */           if (">=".equals(sign))
/* 215 */             return d1.compareTo(d2) != -1 ? "true" : "false";
/* 216 */           if ("<=".equals(sign))
/* 217 */             return d1.compareTo(d2) != 1 ? "true" : "false";
/*     */         }
/*     */         catch (Exception e) {
/*     */ 
/*     */ 
/*     */         }
/* 243 */       }return "false";
/*     */     }
/*     */ 
/*     */     private static boolean isEquals(String str1, String str2)
/*     */     {
/* 256 */       if (str1.equals(str2)) {
/* 257 */         return true;
/*     */       }
/* 259 */       String[] dass = str1.split("!!!!!");
/* 260 */       for (int i = 0; i < dass.length; i++) {
/* 261 */         String das = dass[i];
/* 262 */         if (das.equals(str2)) {
/* 263 */           return true;
/*     */         }
/*     */       }
/* 266 */       return false;
/*     */     }
/*     */ 
/*     */     public static boolean isNumberString(String str)
/*     */     {
/* 276 */       if (isEmpty(str))
/* 277 */         return false;
/* 278 */       str = str.trim();
/* 279 */       int i = 0;
/* 280 */       for (int n = str.length(); i < n; i++) {
/* 281 */         char c = str.charAt(i);
/* 282 */         if (!Character.isDigit(c))
/* 283 */           return false;
/*     */       }
/* 285 */       return true;
/*     */     }
/*     */ 
/*     */     public static String trimAll(String str)
/*     */     {
/* 295 */       return str.replaceAll(" ", "");
/*     */     }
/*     */ 
/*     */     public static String trimEnter(String str)
/*     */     {
/* 305 */       return str.replaceAll("\n", "");
/*     */     }
/*     */ 
/*     */     public static String getStringValue(Object obj) {
/* 309 */       return obj == null ? "" : obj.toString();
/*     */     }
/*     */ 
/*     */     public static String replace(String sourceStr, String targetStr, String str2, int count)
/*     */     {
/* 324 */       StringBuffer sb = new StringBuffer(sourceStr + " ");
/* 325 */       int totalCount = findStrCount(sb.toString(), targetStr);
/* 326 */       if (count > totalCount) {
/* 327 */         return sb.toString().trim();
/*     */       }
/* 329 */       int startIndex = findSubStrIndex(sb.toString(), targetStr, count);
/* 330 */       int endIndex = startIndex + targetStr.length();
/* 331 */       sb.replace(startIndex, endIndex, str2);
/* 332 */       return sb.toString();
/*     */     }
/*     */ 
/*     */     public static String replaceAll(String sourceStr, String targetStr, String str2)
/*     */     {
/* 344 */       int totalCount = findStrCount(sourceStr, targetStr);
/* 345 */       for (int i = 1; i <= totalCount; i++) {
/* 346 */         sourceStr = replace(sourceStr, targetStr, str2, totalCount - i);
/*     */       }
/* 348 */       return sourceStr;
/*     */     }
/*     */ 
/*     */     public static List split(String str, String splitStr)
/*     */     {
/* 359 */       ArrayList list = new ArrayList();
/* 360 */       String[] ss = str.split(splitStr);
/* 361 */       for (int i = 0; i < ss.length; i++) {
/* 362 */         list.add(ss[i]);
/*     */       }
/* 364 */       return list;
/*     */     }
/*     */ 
/*     */     public static int getRightIndex(String sourceStr, String zuoStr, int signIndex, String youStr)
/*     */     {
/* 381 */       int zuoIndex = findSubStrIndex(sourceStr, zuoStr, signIndex);
/* 382 */       String s = subString(sourceStr, 0, zuoIndex, true);
/* 383 */       int youCount = findStrCount(s, youStr);
/* 384 */       return youCount + 1;
/*     */     }
/*     */ 
/*     */     public static int findSubStrIndex(String sourceStr, String subStr, int count)
/*     */     {
/* 396 */       int fromIndex = -1;
/* 397 */       int i = 1;
/* 398 */       while (sourceStr.indexOf(subStr, fromIndex + 1) != -1) {
/* 399 */         fromIndex = sourceStr.indexOf(subStr, fromIndex + 1);
/* 400 */         i++;
/* 401 */         if (i > count) {
/*     */           break;
/*     */         }
/*     */       }
/* 405 */       return fromIndex;
/*     */     }
/*     */ 
/*     */     public static String subString(String str, int beginIndex, int endIndex, boolean isInclude)
/*     */     {
/* 419 */       str = str + " ";
/* 420 */       if (isInclude)
/* 421 */         str = str.substring(beginIndex, endIndex + 1);
/*     */       else
/* 423 */         str = str.substring(beginIndex + 1, endIndex);
/* 424 */       return str.trim();
/*     */     }
/*     */ 
/*     */     public static String truncationString(String str, int startIndex, int endIndex)
/*     */     {
/* 435 */       StringBuffer sb = new StringBuffer();
/* 436 */       str = str + " ";
/* 437 */       sb.append(str.substring(0, startIndex));
/* 438 */       sb.append(str.substring(endIndex + 1, str.length()));
/* 439 */       return sb.toString();
/*     */     }
/*     */ 
/*     */     public static int findStrCount(String sourceStr, String paramStr)
/*     */     {
/* 450 */       if (isEmpty(paramStr)) {
/* 451 */         return -1;
/*     */       }
/* 453 */       int x = 0;
/* 454 */       int index = sourceStr.indexOf(paramStr, 0);
/* 455 */       while (index != -1) {
/* 456 */         x++;
/* 457 */         index = sourceStr.indexOf(paramStr, index + 1);
/*     */       }
/* 459 */       return x;
/*     */     }
/*     */ 
/*     */     public static String findBetween(String sourceStr, String startStr, String endStr)
/*     */     {
/* 471 */       return findBetween(sourceStr, startStr, 1, endStr, 1);
/*     */     }
/*     */ 
/*     */     public static String findBetween(String sourceStr, String startStr, int startLookCount, String endStr, int endLookCount)
/*     */     {
/* 487 */       sourceStr = " " + sourceStr + " ";
/* 488 */       String s = "";
/* 489 */       int startIndex = sourceStr.indexOf(startStr);
/* 490 */       int endIndex = sourceStr.indexOf(endStr);
/* 491 */       if ((startIndex == -1) || (endIndex == -1)) {
/* 492 */         return s;
/*     */       }
/* 494 */       int temp = 0;
/* 495 */       startIndex = -1;
/* 496 */       endIndex = -1;
/* 497 */       while (temp < startLookCount) {
/* 498 */         startIndex = sourceStr.indexOf(startStr, startIndex + 1);
/* 499 */         temp++;
/*     */       }
/* 501 */       temp = 0;
/* 502 */       while (temp < endLookCount) {
/* 503 */         endIndex = sourceStr.indexOf(endStr, endIndex + 1);
/* 504 */         temp++;
/*     */       }
/* 506 */       if (startIndex + startStr.length() + 1 < endIndex)
/* 507 */         s = sourceStr.substring(startIndex + startStr.length(), endIndex);
/*     */       else {
/* 509 */         s = sourceStr.substring(endIndex + endStr.length(), startIndex);
/*     */       }
/* 511 */       return s;
/*     */     }
/*     */ 
/*     */     public static Object calculateStr(String strExp)
/*     */       throws Exception
/*     */     {
/* 526 */       return null;
/*     */     }
/*     */ 
/*     */     public static boolean isEmpty(String str) {
/* 530 */       return (str == null) || (str.trim().equals(""));
/*     */     }
/*     */   }
/*     */ }

/* Location:           D:\work\kingdee\enable\富国基金\fuguo_lib.jar
 * Qualified Name:     com.kingdee.eas.lifetime.util.edcommonutils.EDcommonUtils
 * JD-Core Version:    0.6.0
 */